package 链表;

/*
 * https://leetcode-cn.com/problems/reverse-linked-list/
 * */

public class _206_反转链表 {

	public ListNode reverseList(ListNode head) {

		if (head == null) {
			return null;
		}
		if (head.next == null) {
			return head;
		}
//						//newHead  4
//						//head  3
//		ListNode newHead = this.reverseList(head.next);
//		head.next.next = head;
//		head.next = null;
//		return newHead;

		ListNode prevListNode = null;
		ListNode currNode = head;
		while (currNode != null) {
			ListNode nextListNode = currNode.next;
			currNode.next = prevListNode;
			prevListNode = currNode;
			currNode = nextListNode;
		}

		return prevListNode;

	}

}
